﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Main.Master" Inherits="System.Web.Mvc.ViewPage<Ecommerce.Admin.Models.ArticleViewModel>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	Danh sách tin tức
</asp:Content>
<%@ Import Namespace="Ecommerce.Lib.Paging" %>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

    <form action="" method="POST" id="adminForm" name="adminForm">
    <input type="hidden" name="multi_del" id="multi_del" value="" />
    <div style="width:100%; margin:0 auto;">

        <style type="text/css">
            .Breadcrumb { padding-top: 6px; padding-bottom: 6px; }
            .Breadcrumb ul, .Breadcrumb li { list-style: none outside none; margin: 0; padding: 0; }
            .Block ul li { margin-top: 5px; }
            .Breadcrumb li { display: inline; padding-left: 6px; }
            .Breadcrumb li a{ background: url("/Content/Images/breadcrumbsep.gif") no-repeat scroll right center transparent; color: #005FA3; font-weight: normal; padding-right: 10px; text-decoration: none; }
            .Breadcrumb li a:hover{ text-decoration: underline; }
        </style>

        <div id="Breadcrumb" class="Block Breadcrumb ui-widget-content ui-corner-top ui-corner-bottom">
            <ul>
                <li><a href="#">Trang chủ</a></li><li>Danh sách sản phẩm</li>
            </ul>
        </div>
        <div style="clear: both;"></div>

        <div id="ctl00_cph_Main_Content" style="width:100%; height:100%;"><div id="ctl00_cph_Main_ctl00_ContentPane" style="vertical-align:top;">
                <div id="ctl00_cph_Main_ctl00_ctl00_MenuTab_divSubMenu" class="ui-widget-content ui-corner-top ui-corner-bottom" style="margin: 5px 0px 5px 0px; height: 25px;">
                    <div style="padding: 5px; float: right;">
                        <% Html.RenderPartial("Head"); %>
                    </div>
                </div>
                <div class="ui-widget-content ui-corner-top ui-corner-bottom">
                    <div id="toolbox">
                        <div class="header" style="float:left;">
                            <img id="ctl00_cph_Main_ctl00_ctl00_toolbox_imgHeader" src="/Content/Images/header/icon-news.png" style="border-width: 0px;">
                            <span id="ctl00_cph_Main_ctl00_ctl00_toolbox_lblTitle">Danh sách tin tức</span>
                        </div>
                        <div style="float:right;">

                            <table class="toolbar">
                                <tbody>
                                    <tr>                                      
                                        <td align="center">
                                            <a id="ctl00_cph_Main_ctl00_ctl00_toolbox_rptAction_ctl02_lbtAction" title="Thêm mới" class="toolbar" href="/Article/Create"><span id="ctl00_cph_Main_ctl00_ctl00_toolbox_rptAction_ctl02_lblAction" title="Thêm mới" class="Icon-32-Add"></span>Thêm mới</a>
                                        </td>

                                        <td align="center">
                                            <a onclick="" id="" title="Xóa" class="toolbar multi_del" href="#"><span id="ctl00_cph_Main_ctl00_ctl00_toolbox_rptAction_ctl03_lblAction" title="Xóa" class="Icon-32-Delete"></span>Xóa</a>
                                        </td>

                                    </tr>
                                </tbody></table>

                        </div>
                    </div>
                </div>


                <div class="ui-widget-content ui-corner-top ui-corner-bottom" style="padding: 2px; margin: 5px 0px 5px 0px;">
                    <div>
                        <table style="border-collapse: collapse; margin: 5px 0px;" border="0" width="100%">
                            <tbody><tr>
                                    <td colspan="2">
                                        <div style="padding-left: 5px; font-weight: bold;">
                                            Tổng số tin tức: <span style="color: #A52A2A;"><%=ViewData["RecordInPage"]%></span> / <span style="color: #333;"><%=ViewData["TotalRecord"]%></span>
                                        </div>
                                        <table class="SearchForm">
                                            <tbody><tr>
                                                    <td>
                                                        <input name="txtSearch" value="<%=ViewData["txtSearch"] %>" id="txtSearch" style="width: 200px;" type="text"/>
                                                        <input name="btnSearch" value="Tìm kiếm" id="btnSearch" type="button"/>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td style="height: 20px;">
                                                        <a href="#">Tìm kiếm nâng cao</a>
                                                        |
                                                        <a href="#">Bỏ lọc</a>
                                                    </td>
                                                </tr>
                                            </tbody></table>
                                    </td>
                                </tr>
                                <tr>
                                    <td>

                                        <table class="LetterSort" border="0" cellpadding="0" cellspacing="2">
                                            <tbody>
                                                <tr>
                                                    <td width="3%">
                                                        <a href="#" class="SortLink ">#</a>
                                                    </td>
                                                    <% foreach(var ch in Model.Filters){ %>
                                                    <td width="3%">
                                                        <a href="/Article/Filter/<%=ch %>" class="SortLink "><%=ch %></a>
                                                    </td>                               
                                                    <% } %>                     
                                                    <td width="3%">
                                                        <a href="/Article/" class="SortLink">Bỏ lọc</a>
                                                    </td>
                                                </tr>
                                            </tbody>
                                        </table>

                                    </td>
                                    <td class="GroupTitle" align="right">
                                          <%
                                                int[] pageSizeList = { 1, 5, 10, 15, 20, 25, 50, 100 };
                                            %>
                                            Hiển thị <%= Html.DropDownList("PageSize", new SelectList(pageSizeList, Model.Articles.PageSize), new { onchange = "$j('form').submit();" })%>
                                        &nbsp;
                                    </td>
                                </tr>
                                <tr>
                                    <td style="height: 5px;">
                                    </td>
                                </tr>
                            </tbody></table>
                    </div>
                    <div>
                        <div>
                            <table class="adminlist" rules="all" id="ctl00_cph_Main_ctl00_ctl00_ctl00_grvProducts" style="width: 100%; border-collapse: collapse;" border="1" cellspacing="0">
                                <tbody>
                                    <tr>
                                        <th scope="col">#</th><th scope="col">
                                            <input id="checkAll" name="checkAll" onclick="" type="checkbox">
                                        </th>
                                        <th scope="col">Tiêu đề tin tức</th>
                                        <th scope="col">Tên danh mục</th>                                      
                                        <th scope="col">Ngày đăng</th>  
                                        <th scope="col">Trạng thái</th>                                                                                
                                        <th scope="col">Thao tác</th>
                                    </tr>
                                    <% int stt = 0; %>
                                    <% foreach (var item in Model.Articles)
                                       { %>
                                    <tr class="row0">
                                        <td class="Id" style="width: 20px;" align="center">
                                            <%= stt++ %>                                            
                                        </td>
                                        <td style="width: 8px;" align="center">
                                            <input type="checkbox" class="table_id" value="<%=item.ID %>"/>
                                        </td>                                       
                                        <td class="Code" style="width: 180px;padding-left:5px" align="left">
                                            <a href="/Article/Edit/<%=item.ID %>"><%= Html.Encode(item.Title) %></a>
                                        </td>
                                        <td style="width: 150px;">
                                            <% if (item.CategoryID == null)
                                               { %>
                                               ___
                                            <%}
                                               else
                                               { %>
                                            <%= Html.Encode(item.ArticleCategory.Title)%>
                                            <%} %>
                                        </td>    
                                        <td class="RetailPrice" style="width: 70px;" align="center">
                                            <%=item.AddDate %>
                                        </td>                                     
                                        <td class="RetailPrice" style="width: 70px;" align="center">
                                            <div class="imgs_<%=item.ID %>"><%= item.Status == true ? "<img src='/Content/Images/icon_active.png' style='cursor:pointer' title='Hiển thị' class='changeStatus' id='" + item.ID + "' />" : "<img style='cursor:pointer' title='Không hiển thị' src='/Content/Images/icon_inactive.png' class='changeStatus' id='" + item.ID + "' />"%></div>
                                        </td>                                                                                                                       
                                        <td style="width: 120px;" align="center">
                                            <span style="display: none;">
                                                <a id="" href="#" onclick="" class="Action" title="Cập nhật tin tức này">Cập nhật</a> | </span>
                                                <a href="/Article/Edit/<%=item.ID %>" class="Action" title="Chỉnh sửa sản phẩm này">Chỉnh sửa</a> | <a href="#" onclick="deleteArticle('<%=item.ID %>')" class="Action" title="Xóa tin này">Xóa</a>
                                        </td>
                                    </tr>
                                    <% } %>
                                </tbody>
                            </table>
                        </div>
                    </div>

                    <link rel="Stylesheet" href="admin.aspx_files/pagenavigation.css" type="text/css">
                    <div class="PageNavigation" style="margin-bottom: 10px; margin-top: 10px;" align="center">                      
                    <%= Html.Pager(Model.Articles.PageSize, Model.Articles.PageNumber, Model.Articles.TotalItemCount)%>
                    </div>
                </div>

                <div class="ui-widget-content ui-corner-top ui-corner-bottom">
                    <div id="toolbox">
                        <div class="header" style="float:left;">
                            <img id="Img1" src="/Content/Images/header/icon-news.png" style="border-width: 0px;">
                            <span id="ctl00_cph_Main_ctl00_ctl00_toolbox2_lblTitle">Danh sách tin tức</span>
                        </div>
                        <div style="float:right;">
                            <table class="toolbar">
                                <tbody>
                                    <tr>                                      
                                        <td align="center">
                                            <a id="A1" title="Thêm mới" class="toolbar" href="/Product/Create"><span id="Span1" title="Thêm mới" class="Icon-32-Add"></span>Thêm mới</a>
                                        </td>

                                        <td align="center">
                                            <a onclick="" id="A2" title="Xóa" class="toolbar multi_del" href="#"><span id="Span2" title="Xóa" class="Icon-32-Delete"></span>Xóa</a>
                                        </td>

                                    </tr>
                                </tbody>
                                </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    </form>
<script type="text/javascript">
    $j(function() {
        $j("#checkAll").click(function() {
            var checked_status = this.checked;
            $j(".table_id").each(function() {
                this.checked = checked_status;
            });
        });
        $j(".multi_del").click(function() {
            var list_data_id = "";
            var a = new Array();
            $j.each($j(".table_id:checked"), function(index, item) {
                var id = $j(item).attr("value");
                a.push(id);
                list_data_id = a.join(';');
            });
            $j("#multi_del").val(list_data_id);
            if ($j("#multi_del").val() == "") {
                alert("Bạn phải chọn ít nhất một tin tức");
            } else {
            if (confirm("Bạn có muốn xóa những tin tức này không?")) {                
                $j.ajax({
                    type: "GET",
                    url: "/Article/DeleteMultiArticle",
                    data: { id: $j("#multi_del").val() },
                    dataType: "json",
                    success: function(data) {
                        if (data == true) {
                            window.location = "/Article/";
                        }
                    }
                });
                return false;
            }
            }
            

        })
        $j("#btnSearch").click(function() {
        window.location = '/Article/Search/' + $j("#txtSearch").val();
        });
        $j(".changeStatus").live("click", function() {
            var pId = this.id;
            $j.ajax({
                url: "/Article/ChangeStatus",
                type: "POST",
                data: { id: this.id },
                success: function(data) {
                    $j(".imgs_" + pId).html("");
                    $j(".imgs_" + pId).html(data);
                }
            });
        });
    });
    function deleteArticle(e) {
        if (confirm("Bạn có muốn xóa tin này?")) {
            window.location = "/Article/Delete/"+e;
        }
    }
    
      
</script>

</asp:Content>
